package com.sumainfor.pc.market.controller;

import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.pc.market.service.HousingService;
import com.sumainfor.pc.market.service.HousingauditService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * @Author Xfma
 * @Date 2018年11月7日
 * @Describe 工程部查询房源配置
 */
@Controller
@RequestMapping("/key/Haudit")
public class HousingauditController implements Serializable {


    Logger log = LoggerFactory.getLogger(HousingauditController.class);// 日志
    @Autowired
    HousingauditService hservice;

    @Autowired
    HousingService HousingService;

    /**
     * @return
     * @Author Xfma
     * @Date 2018年11月7日
     * @Describe 查询所有的房源归属
     */
    @ResponseBody
    @RequestMapping("getCommNi")
    public JsonResult getCommNi() {

        System.err.println("123");

        return hservice.getCommNi();
    }

    /**
     * 分页查询所有待审核房源
     *
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("/getHousing")
    public JsonResult getHousing(@RequestParam Map<String, Object> params, Pager pager) throws Exception {

        System.out.println("params---->" + params);


        return hservice.getHousing(params, pager);
    }

    /**
     * 查询待装修中已选择的房源
     *
     * @param params
     * @return
     */
    @ResponseBody
    @RequestMapping("/getHousingByFinState")
    public JsonResult getHousingByFinState() throws Exception {

        return hservice.getHousingByFinState();
    }


    /**
     * 查询管家id
     *
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("/getSysUserId")
    public JsonResult getSysUserId(@RequestParam Map<String, Object> params) throws Exception {

        return hservice.getSysUserId(params);
    }

    /**
     * 审核房源
     *
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @PostMapping("updateHousingState")
    public JsonResult updateHousingState(@RequestBody Map<String, Object> params) throws Exception {


        return hservice.updateHousingState(params);
    }

    /**
     * 获取项目 名称 和房的房屋好号
     *
     * @param huIds
     * @return
     */
    @RequestMapping("/getProjectNameAndHousingConf")
    @ResponseBody
    public JsonResult getProjectNameAndHousingConf(@RequestParam List<String> huIds) {
        if (huIds == null || huIds.isEmpty()) {
            return JsonResult.error("参数错误");
        }
        return hservice.getProjectNameAndHousingConf(huIds);
    }

    /**
     * 根据房源编号 分页 模糊 条件查询房源信息
     *
     * @param huIds
     * @return
     */
    @ResponseBody
    @GetMapping("/getCommunityList")
    public JsonResult getCommunityList(@RequestParam List<String> huIds) {
        System.out.print("传递到服务被调用者的参数:" + huIds);
        return hservice.getCommunityList(huIds);
    }


    /**
     * 按照房源编号查询房源详细信息
     *
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("getListingDetails")
    public JsonResult getListingDetails(@RequestParam Map<String, Object> params) throws Exception {

        return hservice.getListingDetails(params);
    }

    /**
     * 新增房源配置
     *
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @PostMapping("saveConInfo")
    public JsonResult saveConInfo(@RequestBody Map<String, Object> params) throws Exception {

        return hservice.saveConInfo(params);
    }


    /**
     * 按照房源配置id加房源配置子id 删除一个房源配置
     *
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("deleteConInfo")
    public JsonResult deleteConInfo(@RequestParam Map<String, Object> params) throws Exception {

        return hservice.deleteConInfo(params);
    }

    /**
     * 按照房源配置id加房源配置子id 修改一个房源配置
     *
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @PostMapping("updateConInfo")
    public JsonResult updateConInfo(@RequestBody Map<String, Object> params) throws Exception {

        return hservice.updateConInfo(params);
    }

    /**
     * 选中时按照房源id改变装填
     *
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("updateHousingByFinState")
    public JsonResult updateHousingByFinState(@RequestParam Map<String, Object> params) throws Exception {

        return hservice.updateHousingByFinState(params);
    }

    /**
     * 创建装修计划的时候新增房源的无线网络电视等
     *
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @PostMapping("saveCon_Info")
    public Map<String, Object> saveCon_Info(@RequestBody Map<String, Object> params) throws Exception {

        return hservice.saveCon_Info(params);
    }

    /**
     * 创建装修计划的时候新增房源的无线网络电视等
     *
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @PostMapping("getHougingbyhid")
    public Map<String, Object> getHougingbyhid(@RequestBody Map<String, Object> params) throws Exception {

        return hservice.getHougingbyhid(params);
    }

    /**
     * 按条件批次id 和房源装修状态查询房源
     *
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @PostMapping("getDecoratePlanInfoResult")
    public Map<String, Object> getDecoratePlanInfoResult(@RequestBody Map<String, Object> params) throws Exception {

        return hservice.getDecoratePlanInfoResult(params);
    }

    /**
     * 按条件批次id 是否录入其他费用的房源
     *
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @PostMapping("postmap")
    public Map<String, Object> postmap(@RequestBody Map<String, Object> params) throws Exception {

        return hservice.postmap(params);
    }

    /**
     * 设置是否可以预销
     *
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @PostMapping("updatehousingtt")
    public Map<String, Object> updatehousingtt(@RequestBody Map<String, Object> params) {

        return hservice.updatehousingtt(params);
    }

    /**
     * 设置是否可以预销
     *
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("gettcmkt_housingByHouId")
    public Map<String, Object> gettcmkt_housingByHouId(@RequestParam Map<String, Object> params) {

        return hservice.gettcmkt_housingByHouId(params);
    }

    /**
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("updatehousingByHousId")
    public Map<String, Object> updatehousingByHousId(@RequestParam Map<String, Object> params) {

        return hservice.updatehousingByHousId(params);
    }


    /**
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @PostMapping("gethousingByHouId")
    public JsonResult gethousingByHouId(@RequestBody List<Map<String, Object>> params) {

        return hservice.gethousingByHouId(params);
    }

    //////////////以下运营部

    /**
     * 根据位置查询小区
     **/
    @ResponseBody
    @GetMapping("getComName")
    public JsonResult getComName(@RequestParam Map<String, Object> params) {

        return hservice.getComName(params);
    }

    /**
     * 根据小区查询楼号
     **/
    @ResponseBody
    @GetMapping("getBuilding")
    public JsonResult getBuilding(@RequestParam Map<String, Object> params) {

        return hservice.getBuilding(params);
    }


    /**
     * 根据小区查询楼号
     **/
    @ResponseBody
    @GetMapping("getRoom")
    public JsonResult getRoom(@RequestParam Map<String, Object> params) {

        return hservice.getRoom(params);
    }


    /**
     * 获得验房列表
     *
     * @param params
     * @param pager
     * @return
     * @throws Exception
     */
    @ResponseBody
    @PostMapping("/gethousingByids")
    public JsonResult gethousingByids(@RequestBody Map<String, Object> params, Pager pager) throws Exception {

        System.out.println("params---->" + params);


        return hservice.gethousingByids(params, pager);
    }


    /**
     * 新增房源配置
     *
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @PostMapping("/saveHousingCon")
    public JsonResult saveHousingCon(@RequestBody Map<String, Object> params) {

        System.out.println("params---->" + params);
        return hservice.saveHousingCon(params);
    }


    /**
     * 新增新增厨房区域(管家验房的图片)
     *
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @PostMapping("/saveHouingKitchenFile")
    public JsonResult saveHouingKitchenFile(@RequestBody Map<String, Object> params) {

        System.out.println("params---->" + params);
        return hservice.saveHouingKitchenFile(params);
    }


    /**
     * 查询厨房区域(管家验房的图片)
     *
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("/gethousingKitchenFileByid")
    public JsonResult gethousingKitchenFileByid(@RequestParam Map<String, Object> params) {

        System.out.println("params---->" + params);
        return hservice.gethousingKitchenFileByid(params);
    }

    /**
     * 新增新增卫生间区域(管家验房的图片)
     *
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @PostMapping("/saveHouingToiletFile")
    public JsonResult saveHouingToiletFile(@RequestBody Map<String, Object> params) {

        System.out.println("params---->" + params);
        return hservice.saveHouingToiletFile(params);
    }


    /**
     * 查询厨房区域(管家验房的图片)
     *
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("/gethousingToiletFileByid")
    public JsonResult gethousingToiletFileByid(@RequestParam Map<String, Object> params) {

        System.out.println("params---->" + params);
        return hservice.gethousingToiletFileByid(params);
    }


    /**
     * 新增新增餐厅区域(管家验房的图片)
     *
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @PostMapping("/saveHouingDiningFile")
    public JsonResult saveHouingDiningFile(@RequestBody Map<String, Object> params) {

        System.out.println("params---->" + params);
        return hservice.saveHouingDiningFile(params);
    }


    /**
     * 新增房源主图片
     *
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @PostMapping("/saveHouingShowImg")
    public JsonResult saveHouingShowImg(@RequestBody Map<String, Object> params) {

        System.out.println("params---->" + params);
        return hservice.saveHouingShowImg(params);
    }

    /**
     * 新增房源户型图片
     *
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @PostMapping("/saveHouingHouseImg")
    public JsonResult saveHouingHouseImg(@RequestBody Map<String, Object> params) {

        System.out.println("params---->" + params);
        return hservice.saveHouingHouseImg(params);
    }

    /**
     * 查询餐厅区域(管家验房的图片)
     *
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("/gethousingDiningFileByid")
    public JsonResult gethousingDiningFileByid(@RequestParam Map<String, Object> params) {

        System.out.println("params---->" + params);
        return hservice.gethousingDiningFileByid(params);
    }

    /**
     * 查询房间住(管家验房的图片)
     *
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("/gethousingShowImgByid")
    public JsonResult gethousingShowImgByid(@RequestParam Map<String, Object> params) {

        System.out.println("params---->" + params);
        return hservice.gethousingShowImgByid(params);
    }

    /**
     * 查询房间住(管家验房的图片)
     *
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("/gethousingHouseImgByid")
    public JsonResult gethousingHouseImgByid(@RequestParam Map<String, Object> params) {

        System.out.println("params---->" + params);
        return hservice.gethousingHouseImgByid(params);
    }



    /**
     * 查询各个房间(管家验房的图片)
     *
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("/getHousingConInfo")
    public JsonResult getHousingConInfo(@RequestParam Map<String, Object> params) {

        System.out.println("params---->" + params);
        return hservice.getHousingConInfo(params);
    }

    /**
     * 新增各个房间(管家验房的图片)
     *
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @PostMapping("/saveHouingInfoFile")
    public JsonResult saveHouingInfoFile(@RequestBody Map<String, Object> params) {

        System.out.println("params---->" + params);
        return hservice.saveHouingInfoFile(params);
    }


    /**
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("/getocuntHouging")
    public JsonResult getocuntHouging(@RequestParam Map<String, Object> params) {
        System.out.println("params---->" + params);
        return hservice.getocuntHouging(params);
    }

    /**
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("/updateAccepted")
    public JsonResult updateAccepted(@RequestParam Map<String, Object> params) {
        System.out.println("params---->" + params);
        return hservice.updateAccepted(params);
    }


    /**
     * @param params
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("/gethousingByState")
    public JsonResult gethousingByState(@RequestParam Map<String, Object> params) {
        System.out.println("params---->" + params);
        return hservice.gethousingByState(params);
    }

    /**
     * 功能描述:
     * 根据房源配置获取所有房源资料(字段可扩展)
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/5/9 13:53
     */
    @ResponseBody
    @GetMapping("/getAllHousingConLists")
    public JsonResult getAllHousingConLists(){
        JsonResult result=new JsonResult();
        return result.put(HousingService.getAllHousingConLists());
    }

    /**
     * 功能描述: 
     * 根据房源编号获取房源资料
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/5/10 11:31
     */
    @ResponseBody
    @GetMapping("/getRepairMaps")
    public JsonResult getRepairMaps(@RequestParam Map<String,Object>params){
        JsonResult result=new JsonResult();
        if(!FieldCheckUtil.isMapFieldNotNull(params,new String[]{"HouId"})){
            result.putFailed("HouId不能为空！");
            return  result;
        }
        result.put(HousingService.getHousingMap(params));
        return result;
    }


}
